package StudyCode.summary.myfile;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.PosixFileAttributeView;
import java.nio.file.attribute.PosixFileAttributes;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.Set;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class UsingPosixFilePermissionsFromString {
	public static void main(String[] args) {

		PosixFileAttributes attr = null;
		Path path = Paths.get("E:\\迅雷下载\\test1.txt");
		try {
			attr = Files.getFileAttributeView(path, PosixFileAttributeView.class).readAttributes();
		} catch (IOException e) {
			System.err.println(e);
		}
		System.out.println("文件所有者: " + attr.owner().getName());
		System.out.println("文件分组: " + attr.group().getName());
		System.out.println("文件权限: " + attr.permissions().toString());

		Path new_path = Paths.get("E:\\迅雷下载\\test1.txt");
		Set<PosixFilePermission> permissions = PosixFilePermissions.fromString("rw-r--r--");
		try {
			Files.setPosixFilePermissions(new_path, permissions);
		} catch (IOException e) {
			System.err.println(e);
		}

	}
}
